<?php

$rank_check = 1;
$page_title = "Clubs";
include "header.inc.php";

echo $openHTML;

if (!$page) { $page = 1; }
$start = $page * 20 - 20;

$getmemberdata = fetch("SELECT * FROM club_members2 WHERE user = '$userid' AND game = '$game'");

$getclub = mysql_query("SELECT * FROM clubs2 WHERE game = '$game' ORDER BY members DESC LIMIT $start,20");
$numClubs = mysql_num_rows(mysql_query("SELECT * FROM clubs2 WHERE game = '$game'"));
while ($findclubs = mysql_fetch_array($getclub))
{
	$cellcolor = alternate($cellcolor,"$reallyLight","$maincellColor");
	$owner = fetch("SELECT display_name FROM members2 WHERE id = '$findclubs[owner]' AND game = '$game'");

	$clubList .= "<TR BGCOLOR=\"$cellcolor\"><TD
HEIGHT=40> <P><A HREF=\"$base_url/club.php?game=$game&clubid=$findclubs[id]\"><B>$findclubs[name]</b></A> - <font size=-1><i>owned by $owner[display_name]</i> ($findclubs[members] members)</font><BR><FONT
SIZE=\"-1\">&#187; $findclubs[motto]</FONT></P> </TD></TR>";
}

ECHO <<<END

<CENTER><BR> <TABLE BGCOLOR="$tableOutline" CELLSPACING=1 CELLPADDING=0 WIDTH=520> <TR
BGCOLOR="$topAndBottomBG"> <TD COLSPAN=4 HEIGHT=50> <p align=center><FONT SIZE="+2"
COLOR="#FFFFFF"><b>--Clubs List--</b></FONT></p></TD></TR>

$clubList

<TR> <TD COLSPAN=4 HEIGHT=30 BGCOLOR="$topAndBottomBG"> <p align=center><FONT SIZE="-1"
COLOR="#FFFFFF"><I>(You must be at least 13 to join the $gameName2
Clubs!)</I></FONT></p> </TD> </TR> </TABLE> <BR> </CENTER>

END;

if ($numClubs > 20) { $pages = ceil($numClubs / 50); }
if ($pages > 1)
{
	for ($p = 1; $p <= $pages; $p++)
	{
		if ($p == 1) { $list_pages = "<p align=center>Pages ["; }
		if ($p < $pages) { $list_pages .= "<a href=$base_url/listclubs.php?game=$game&page=$p>$p</a>, "; }
		if ($p == $pages) { $list_pages .= "<a href=$base_url/listclubs.php?game=$game&page=$p>$p</a>"; $list_pages .= "]</p>"; }
	}
}

print "$list_pages";

echo $closeHTML;

?>